<?php

namespace App\Http\Resources\Api;

use App\Models\Tenant;
use Illuminate\Http\Resources\Json\JsonResource;

class TenantResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        $province = \DB::table('china_area')->where(['code' => $this->province_id])->first();
        $city = \DB::table('china_area')->where(['code' => $this->city_id])->first();
        $district = \DB::table('china_area')->where(['code' => $this->district_id])->first();

        return [
            'id'=>$this->id,
            'name' => $this->name,
            'short_name' => $this->short_name,
            'logo_url' => $this->logo_url,
            'logo_path' => $this->logo_path,
            'contact_number' => $this->contact_number,
            'province' => $province->name,
            'city' => $city->name,
            'district' => $district->name,
            'address' => $this->address,
            'full_address' => $province->name . $city->name . $district->name . $this->address,
            'longitude' => (float)$this->longitude,
            'latitude' => (float)$this->latitude,
        ];
    }
}
